﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.Sys.Orders_Goods
{
    public partial class Info : InfoPage
    {
        BLL.Orders_Goods bll = new BLL.Orders_Goods();
        Model.Orders_Goods model = new Model.Orders_Goods();
        //
        BLL.V_Orders_Goods bllV_Orders_Goods = new BLL.V_Orders_Goods();
        protected Model.V_Orders_Goods modelV_Orders_Goods = new Model.V_Orders_Goods();
        //
        BLL.Orders bllOrders = new BLL.Orders();
        protected bool noFinish = false;
        protected EnumHelper.OrdersState OrderState;
        int GoodsID = 0, ExpectAmount = 0, ActualAmount = 0;
        protected void Page_Load(object sender, EventArgs e) { }
        /// <summary>
        /// 初始化本页Model
        /// </summary>
        public override void Page_Load_DefaultModel()
        {
            model = bll.GetModel(Master.id);
            modelV_Orders_Goods = bllV_Orders_Goods.GetModelList("id=" + Master.id)[0];

            OrderState = (EnumHelper.OrdersState)bllOrders.GetModel(model.OrdersID).State;

            noFinish = OrderState < EnumHelper.OrdersState.BuyFinish;

            GoodsID = model.GoodsID;
            ExpectAmount = model.ExpectAmount;
        }
        /// <summary>
        /// 初始化表单
        /// </summary>
        public override void Form_Default()
        {
            if (Security.InUserType(new List<EnumHelper.UserType>() { EnumHelper.UserType.Buyer, EnumHelper.UserType.Supplier }))
            {//采购员+供货商 看不到：售价
                tr_Price.Visible = false;
                th_Sell.Visible = th_SellPrice.Visible = th_SellPriceSum.Visible = td_ExpectPrice.Visible = td_ExpectPriceSum.Visible = td_ActualPrice.Visible = td_ActualPriceSum.Visible = false;
                if (Security.GetCurrentUserType() == EnumHelper.UserType.Supplier)
                {//供应商 看不到：供货商名称

                }
            }
            if (Security.GetCurrentUserType() == EnumHelper.UserType.Store)
            {//孕婴店  看不到：进价和支付金额
                tr_Price.Visible = false;
                th_Buy.Visible = th_BuyPrice.Visible = th_BuyPriceSum.Visible = td_ExpectBuyPrice.Visible = td_ExpectBuyPriceSum.Visible = td_ActualBuyPrice.Visible = td_ActualBuyPriceSum.Visible = false;
                th_Pay.Visible = td_ExpectPay.Visible = td_ActualPay.Visible = false;
            }

            //显示预计销售数据
            int ExpectGiftNumber=0,ExpectDiscount = 0;
            if (OrderState < EnumHelper.OrdersState.GetMoney)
            {
                ExpectGiftNumber = BLL.Goods.GetGiftNumberSell(GoodsID, ExpectAmount);
                ExpectDiscount = BLL.Goods.GetSellDiscount(GoodsID, ExpectAmount);
                lb_ExpectSellPrice.Text =StringPlus.showMoney_empty( modelV_Orders_Goods.SellPrice);
                lb_ExpectSellPriceSum.Text = StringPlus.showMoney_empty(BLL.Goods.GetSellPriceSum(GoodsID, ExpectAmount));
            }
            else
            {
                ExpectGiftNumber = model.ExpectGiftNumber;
                ExpectDiscount = model.ExpectDiscount;
                lb_ExpectSellPrice.Text = StringPlus.showMoney_empty(model.ExpectPrice);
                lb_ExpectSellPriceSum.Text = StringPlus.showMoney_empty(model.ExpectPriceSum);
            }
            if (ExpectGiftNumber > 0) lb_ExpectGiftNumber.Text = "赠"+ExpectGiftNumber;
            else lb_ExpectGiftNumber.Visible = false;
            if (ExpectDiscount < 100) lb_ExpectDiscount.Text = ExpectDiscount / 10 + "折";
            else lb_ExpectDiscount.Visible = false;

            //显示预计采购数据
            int ExpectBuyGiftNumber = 0, ExpectBuyDiscount = 0;
            if (OrderState < EnumHelper.OrdersState.BuyFinish)
            {
                ExpectBuyGiftNumber = BLL.Goods.GetGiftNumberBuy(GoodsID, ExpectAmount);
                ExpectBuyDiscount = BLL.Goods.GetBuyDiscount(GoodsID, ExpectAmount);
                lb_ExpectBuyPrice.Text = StringPlus.showMoney_empty(modelV_Orders_Goods.BuyPrice);
                lb_ExpectBuyPriceSum.Text = StringPlus.showMoney_empty(BLL.Goods.GetBuyPriceSum(GoodsID, ExpectAmount));
                if (!modelV_Orders_Goods.IsLatePay) lb_ExpectPay.Text = lb_ExpectBuyPriceSum.Text;
            }
            else
            {
                ExpectBuyGiftNumber = model.ExpectBuyGiftNumber;
                ExpectBuyDiscount = model.ExpectBuyDiscount;
                lb_ExpectBuyPrice.Text = StringPlus.showMoney_empty(model.ExpectBuyPrice);
                lb_ExpectBuyPriceSum.Text = StringPlus.showMoney_empty(model.ExpectBuyPriceSum);
                lb_ExpectPay.Text = StringPlus.showMoney_empty(model.ExpectPay);
            }
            if (ExpectBuyGiftNumber > 0) lb_ExpectBuyGiftNumber.Text = "赠" + ExpectBuyGiftNumber;
            else lb_ExpectBuyGiftNumber.Visible = false;
            if (ExpectBuyDiscount < 100) lb_ExpectBuyDiscount.Text = ExpectBuyDiscount/10 + "折";
            else lb_ExpectBuyDiscount.Visible = false;
        }
        /// <summary>
        /// 绑定表单数据【修改时用】
        /// </summary>
        public override void Form_Bind()
        {

        }


    }
}